package com.scf.preloanmanage.service.impl;

import com.scf.entity.History;
import com.scf.preloanmanage.entity.PreLoan;
import com.scf.preloanmanage.mapper.PreLoanMapper;
import com.scf.preloanmanage.service.PreLoanService;
import com.scf.service.HistoryService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author author
 * @create 2021-11-15-10:22
 */
@Service
public class PreLoanServiceImpl implements PreLoanService {

    @Resource
    PreLoanMapper preLoanMapper;

    @Resource
    HistoryService historyService;

    @Override
    public List<PreLoan> getPreLoan(PreLoan preLoan) {
        List<PreLoan> preLoans = preLoanMapper.select(preLoan);
        return preLoans;
    }

    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public boolean update(PreLoan preLoan) {

            int update = preLoanMapper.update(preLoan.getPlid());
            List<PreLoan> select = preLoanMapper.select(preLoan);
            if(update==1)
            {
                History history=new History();
                history.setStep("待进件");
                history.setAgent(preLoan.getSalesman());
                history.setContent("");
                history.setSuggestion(select.get(0).getBorrowDemand().getOpinion());
                history.setProcessingtime(new Date());
                history.setPlid(preLoan.getPlid());
                boolean insert = historyService.insert(history);
                if(insert) {
                    return true;
                }
            }


        return false;
    }
}
